package com.xyauto.theme.bean;

import android.os.Parcel;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.xyauto.theme.App;
import com.xyauto.theme.BuildConfig;
import com.xyauto.theme.utils.SelectManager;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class LocalThemeGroupBean implements IThemeBean, Comparator<String> {

    private String fileName;
    private String previewImage;
    private String apkPath;
    private List<String> previewList;
    private int pos;


    public LocalThemeGroupBean(String fileName, List<String> previewList, String apkPath) {
        previewList.sort(this);
        this.fileName = fileName;
        this.apkPath = apkPath;
        this.previewImage = previewList.get(0);
        this.previewList = previewList;
    }


    public static final Creator<LocalThemeGroupBean> CREATOR = new Creator<LocalThemeGroupBean>() {
        @Override
        public LocalThemeGroupBean createFromParcel(Parcel in) {
            return new LocalThemeGroupBean(in);
        }

        @Override
        public LocalThemeGroupBean[] newArray(int size) {
            return new LocalThemeGroupBean[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    protected LocalThemeGroupBean(Parcel in) {
        fileName = in.readString();
        previewImage = in.readString();
        apkPath = in.readString();
        pos = in.readInt();
        previewList = new ArrayList<>();
        in.readStringList(previewList);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(fileName);
        dest.writeString(previewImage);
        dest.writeString(apkPath);
        dest.writeInt(pos);
        dest.writeStringList(previewList);
    }


    @Override
    public boolean isSelected() {
        return SelectManager.INSTANCE.isSelectTheme(fileName);
    }

    @NonNull
    @Override
    public String getName() {
        return fileName;
    }

    @NonNull
    @Override
    public String getPreviewImage() {
        return previewImage;
    }


    @Nullable
    @Override
    public String getApkPath() {
        return apkPath;
    }

    @Nullable
    @Override
    public String getUrlPath() {
        return null;
    }

    @Override
    public boolean isExists() {
        return true;
    }

    @NonNull
    @Override
    public String getVersion() {
        return App.Companion.findLauncherVer();
    }


    public int getPos() {
        return pos;
    }

    public void setPos(int pos) {
        this.pos = pos;
    }

    @Override
    public int compare(String o1, String o2) {
        return o1.compareTo(o2);
    }

    @Nullable
    @Override
    public List<String> getPreviewImages() {
        return previewList;
    }
}
